package cn.itsource.ymcc.service.impl;

import cn.itsource.ymcc.domain.KillActivity;
import cn.itsource.ymcc.domain.KillCourse;
import cn.itsource.ymcc.mapper.KillActivityMapper;
import cn.itsource.ymcc.mapper.KillCourseMapper;
import cn.itsource.ymcc.service.IKillCourseService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.Date;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author cff
 * @since 2024-06-24
 */
@Service
public class KillCourseServiceImpl extends ServiceImpl<KillCourseMapper, KillCourse> implements IKillCourseService {

    @Autowired
    private KillActivityMapper killActivityMapper;

    @Transactional
    @Override
    public boolean save(KillCourse entity) {
        entity.setCreateTime(new Date());
        KillActivity killActivity = killActivityMapper.selectById(entity.getActivityId());
        entity.setStartTime(killActivity.getBeginTime());
        entity.setEndTime(killActivity.getEndTime());
        entity.setTimeStr(killActivity.getTimeStr());
        return super.save(entity);
    }
}
